using Tools.Modules.Dialogs;
using Tools.Services;
using Tools.Services.Interfaces;
using Tools.Views;
using Prism.Ioc;
using Prism.Modularity;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Threading.Tasks;
using System.Windows;
using Tools.Modules.Navigations;
using Tools.Core;
using AutoMapper;
using Tools.Core.Profiles;
using Tools.Core.Mvvm;

namespace Tools
{
    /// <summary>
    /// App.xaml 的交互逻辑
    /// </summary>
    public partial class App
    {
        protected override Window CreateShell()
        {
            return Container.Resolve<MainWindow>();
        }

        protected override void RegisterTypes(IContainerRegistry containerRegistry)
        {
            AutoMapper.IConfigurationProvider mapperConfig = new MapperConfiguration(cfg =>
            {
                cfg.AddProfile<MailMessageProfile>();
                cfg.AddProfile<MailSenderProfile>();
                cfg.AddProfile<MailReceiverProfile>();
            });
            var mapper = new Mapper(mapperConfig);
            containerRegistry.RegisterInstance<IMapper>(mapper);

            var config = Kits.ReadObject<GlobalConfig>();
            containerRegistry.RegisterInstance<GlobalConfig>(config);

            containerRegistry.RegisterSingleton<DB>();
            containerRegistry.RegisterSingleton<IMessageService, MessageService>();
            containerRegistry.RegisterSingleton<IMailReceiverService, MailReceiverService>();
            containerRegistry.RegisterSingleton<IMailSenderService, MailSenderService>();
            containerRegistry.RegisterSingleton<IMailMessageService, MailMessageService>();
        }

        protected override void ConfigureModuleCatalog(IModuleCatalog moduleCatalog)
        {
            moduleCatalog.AddModule<DialogsModule>();
            moduleCatalog.AddModule<NavigationsModule>();
        }
    }
}
